package com.shopmall.manager.controller;

import com.shopmall.manager.service.CategoryService;
import com.shopmall.model.entity.product.Category;
import com.shopmall.model.vo.common.Result;
import com.shopmall.model.vo.common.ResultCodeEnum;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/admin/product/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    // 构造注入
    //    private final CategoryService categoryService;
    //
    //    public CategoryController(CategoryService categoryService) {
    //        this.categoryService = categoryService;
    //    }

    // 导入
    @PostMapping("/importData")
    public Result<String> importData(MultipartFile file) {
        // 获取上传文件
        String flag = categoryService.importData(file);
        return Result.build(flag, ResultCodeEnum.SUCCESS);
    }

    // 导出
    @GetMapping("/exportData")
    public void exportData(HttpServletResponse response) {
        categoryService.exportData(response);
    }

    // 分类列表，每次查询一层数据
    @GetMapping("/findCategoryList/{id}")
    public Result<List<Category>> findCategoryList(@PathVariable Long id) {
        List<Category> list = categoryService.findCategoryList(id);
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }
}
